package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * JDBC 执行查询语句[DQL];
 * 查询所有用户的用户名，密码，昵称，年龄
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.geConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT username,password,age FROM userinfo";
            //resultset:存放SQL语句的查询结果
            ResultSet r = statement.executeQuery(sql);
            //获取数据
            /*

             */
            while (r.next()){
                String username = r.getString("username");
                String password = r.getString("password");
                int age = r.getInt("age");
                System.out.println(username+"-"+password+"-"+age);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
